<?php

use yii\helpers\Html;
use kartik\widgets\ActiveForm;
use kartik\builder\Form;
use kzo\base\models\statics\EntityModelStatus;
use kzo\base\widgets\ui\bs4\Alert;

/* @var $model common\models\c2\entity\Product */

$regularLangName = \Yii::$app->kzoHelper->getRegularLangName();
$messageName = $model->getMessageName();
?>

<?php
$form = ActiveForm::begin([
    'action' => ['edit', 'id' => $model->id],
    'options' => [
        'id' => $model->getBaseFormName(),
        'data-pjax' => true,
    ]]);
?>

<div class="<?= $model->getPrefixName('form') ?> card bg-light mt-2">
    <div class="card-body">

        <?php if (Yii::$app->session->hasFlash($messageName)): ?>
            <?php if (!$model->hasErrors()) {
                echo Alert::widget([
                    'type' => Alert::TYPE_SUCCESS,
                    'title' => 'Well Down',
                    'icon' => 'fas fa-ok-circle',
                    'body' => Yii::$app->session->getFlash($messageName),
                    'showSeparator' => true,
                    'delay' => 2000
                ]);
            } else {
                echo Alert::widget([
                    'type' => Alert::TYPE_WARNING,
                    'title' => 'Warning!',
                    'icon' => 'fas fa-ok-circle',
                    'body' => Yii::$app->session->getFlash($messageName),
                    'showSeparator' => true,
                ]);
            }
            ?>
        <?php endif; ?>

        <?php
        echo Form::widget([
            'model' => $model,
            'form' => $form,
            'columns' => 4,
            'attributes' => [
                'type' => ['type' => Form::INPUT_DROPDOWN_LIST, 'items' => \common\models\c2\statics\ProductType::getHashMap('id', 'label')],
                'sku' => ['type' => Form::INPUT_TEXT, 'options' => ['placeholder' => $model->getAttributeLabel('sku')]],
                'name' => ['type' => Form::INPUT_TEXT, 'options' => ['placeholder' => $model->getAttributeLabel('name')]],
                'label' => ['type' => Form::INPUT_TEXT, 'options' => ['placeholder' => $model->getAttributeLabel('label')]],
                'attributeset_ids' => [
                    'type' => Form::INPUT_WIDGET,
                    'widgetClass' => '\kartik\widgets\Select2',
                    'options' => [
                        'language' => Yii::$app->language,
                        'data' => \common\models\c2\entity\Attributeset::getHashMap('id', 'label'),
                        'pluginOptions' => [
                            'multiple' => true
                        ],
                    ],
                ],
                'factory_price' => ['type' => Form::INPUT_TEXT, 'options' => ['placeholder' => $model->getAttributeLabel('factory_price')]],
                'supplier_id' => [
                    'type' => Form::INPUT_DROPDOWN_LIST,
                    'items' => \common\models\c2\entity\Supplier::getHashMap('id', 'label'),
                    'options' => [
                        'placeholder' => $model->getAttributeLabel('supplier_id')
                    ]
                ],
                'currency_id' => [
                    'type' => Form::INPUT_DROPDOWN_LIST,
                    'items' => \common\models\c2\entity\Supplier::getHashMap('id', 'label'),
                    'options' => [
                        'placeholder' => $model->getAttributeLabel('supplier_id')
                    ]
                ],
                // 'currency_id' => ['type' => Form::INPUT_TEXT, 'options' => ['placeholder' => $model->getAttributeLabel('currency_id')]],
                'measure_id' => [
                    'type' => Form::INPUT_DROPDOWN_LIST,
                    'items' => \common\models\c2\entity\Supplier::getHashMap('id', 'label'),
                    'options' => [
                        'placeholder' => $model->getAttributeLabel('supplier_id')
                    ]
                ],
                // 'measure_id' => ['type' => Form::INPUT_TEXT, 'options' => ['placeholder' => $model->getAttributeLabel('measure_id')]],
                // 'description' => ['type' => Form::INPUT_WIDGET, 'widgetClass' => '\vova07\imperavi\Widget', 'options' => [
                //     'settings' => [
                //         'minHeight' => 150,
                //         'buttonSource' => true,
                //         'lang' => $regularLangName,
                //         'plugins' => [
                //             'fontsize',
                //             'fontfamily',
                //             'fontcolor',
                //             'table',
                //             'textdirection',
                //             'fullscreen',
                //         ],
                //     ]
                // ],],
                'sold_count' => ['type' => Form::INPUT_TEXT, 'options' => ['placeholder' => $model->getAttributeLabel('sold_count')]],
                'status' => ['type' => Form::INPUT_DROPDOWN_LIST, 'items' => EntityModelStatus::getHashMap('id', 'label')],
                'position' => ['type' => Form::INPUT_WIDGET, 'widgetClass' => '\kartik\touchspin\TouchSpin',],
            ]]);

        echo Form::widget([
            'model' => $model,
            'form' => $form,
            'attributes' => [
                'description' => [
                    'type' => Form::INPUT_WIDGET,
                    'widgetClass' => '\vova07\imperavi\Widget',
                    'options' => [
                        'settings' => [
                            'minHeight' => 150,
                            'buttonSource' => true,
                            'lang' => $regularLangName,
                            'plugins' => [
                                'fontsize',
                                'fontfamily',
                                'fontcolor',
                                'table',
                                'textdirection',
                                'fullscreen',
                            ],
                        ]
                    ],
                ],
            ]
        ]);

        echo Html::submitButton('<i class="fa fa-save"></i> ' . Yii::t('app.c2', 'Save'), ['type' => 'button', 'class' => 'btn btn-primary float-right ml-2']);
        echo Html::a('<i class="fa fa-arrow-left"></i> ' . Yii::t('app.c2', 'Go Back'), ['index'], ['data-pjax' => '0', 'class' => 'btn btn-light float-right', 'title' => Yii::t('app.c2', 'Go Back'),]);
        ?>

    </div>
</div>
<?php ActiveForm::end(); ?>
